﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using EntityObject;
using System.Data;
using SharedLibraries;
using System.Data.SqlClient;
using ThangNM_LIB.FUNC;

namespace DataAccessObject
{
    public class WeddingDAO : DB_SQL_EXT
    {
        public Boolean Insert_Update_Delete(WeddingEO _WeddingEO, Int16 Insert_Update_Delete)
        {
            SqlCommand cmd = new SqlCommand("Wedding_Insert_Update_Delete");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_gWeddingID", _WeddingEO.PK_gWeddingID));
            cmd.Parameters.Add(new SqlParameter("@sName", _WeddingEO.sName));
            cmd.Parameters.Add(new SqlParameter("@sNameEx", _WeddingEO.sNameEx));
            cmd.Parameters.Add(new SqlParameter("@sRelationship", _WeddingEO.sRelationship));
            cmd.Parameters.Add(new SqlParameter("@sNote", _WeddingEO.sNote));
            cmd.Parameters.Add(new SqlParameter("@sEmail", _WeddingEO.sEmail));
            cmd.Parameters.Add(new SqlParameter("@tPartySC", _WeddingEO.tPartySC));
            cmd.Parameters.Add(new SqlParameter("@tPartyLC", _WeddingEO.tPartyLC));
            cmd.Parameters.Add(new SqlParameter("@iGroom", _WeddingEO.iGroom));
            cmd.Parameters.Add(new SqlParameter("@iStatus", _WeddingEO.iStatus));
            cmd.Parameters.Add(new SqlParameter("@Insert_Update_Delete", Insert_Update_Delete));
            return ExecuteNonQuery_RetBool(cmd, true);
        }

        public DataTable SelectBy_iGroom(Int16 _iGroom)
        {
            SqlCommand cmd = new SqlCommand("Wedding_SelectBy_iGroom");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@iGroom", NullEx.getNullValue(_iGroom)));
            return GetDataTable(cmd);
        }

        public WeddingEO SelectItem(Guid _PK_gWeddingID)
        {
            SqlCommand cmd = new SqlCommand("Wedding_SelectItem");
            cmd.CommandType = CommandType.StoredProcedure;
            cmd.Parameters.Add(new SqlParameter("@PK_gWeddingID", _PK_gWeddingID));
            return FunctionDO(GetDataTable(cmd));
        }

        public WeddingEO FunctionDO(DataTable input)
        {
            List<WeddingEO> lst = new List<WeddingEO>();
            lst = (List<WeddingEO>)ConvertEx.ConvertDataTableToListObject<WeddingEO>(input, lst.GetType());
            if (CommonsCheck.ListObject_OK(lst))
                return lst[0];
            else
                return null;
        }
    }
}